/**
 * 该例程将发布turtle1/cmd_vel话题，消息类型geometry_msgs::Twist                   
 */
 
#include <ros/ros.h>
#include <geometry_msgs/Twist.h>

int main(int argc, char **argv)
{
	// ROS节点初始化
	ros::init(argc, argv, "velocity_publishe");

	// 创建节点句柄
	ros::NodeHandle n;

	// 创建一个Publisher，发布名为/turtle1/cmd_vel的topic，消息类型为geometry_msgs::Twist，队列长度10
	ros::Publisher turtle_vel_pub = n.advertise<geometry_msgs::Twist>("/turtle1/cmd_vel", 10);

	// 设置循环的频率
	ros::Rate loop_rate(10);

	ROS_INFO_STREAM_ONCE("loop start");
    ROS_DEBUG_STREAM( "DEBUG message." );
    ROS_INFO_STREAM ( "INFO message."  );
    ROS_WARN_STREAM ( "WARN message."  );
    ROS_ERROR_STREAM( "ERROR message." );
    ROS_FATAL_STREAM( "FATAL message." );
    ROS_INFO_STREAM_NAMED( "named_msg", "INFO named message." );
	//表示为这段信息命名，为了更容易知道这段信息来自那段代码
    ROS_INFO_STREAM_THROTTLE( 2, "INFO throttle message." );
	//设置显示频率，以上代码运行两次输出一次INFO throttle message．
	int count = 0;
	while (ros::ok())
	{
	    // 初始化geometry_msgs::Twist类型的消息
		geometry_msgs::Twist vel_msg;
		vel_msg.linear.x = 0.5;
		vel_msg.angular.z = 0.2;

	    // 发布消息
		turtle_vel_pub.publish(vel_msg);

		ROS_INFO("Publsh turtle velocity command[%0.2f m/s, %0.2f rad/s]", 
				vel_msg.linear.x, vel_msg.angular.z);//输出白颜色的信息，用户信息
/*
		ROS_DEBUG("Publsh turtle velocity command[%0.2f m/s, %0.2f rad/s]", 
				vel_msg.linear.x, vel_msg.angular.z);//这个默认不输出
		ROS_WARN("Publsh turtle velocity command[%0.2f m/s, %0.2f rad/s]", 
				vel_msg.linear.x, vel_msg.angular.z);//输出黄颜色的信息，警告信息
		ROS_ERROR("Publsh turtle velocity command[%0.2f m/s, %0.2f rad/s]", 
				vel_msg.linear.x, vel_msg.angular.z);//输出红颜色的信息，错误
		ROS_FATAL("Publsh turtle velocity command[%0.2f m/s, %0.2f rad/s]", 
				vel_msg.linear.x, vel_msg.angular.z);//输出红颜色的信息，崩溃式错误
*/

/*
		1.ROS_INFO_STREAM(“Hello ROS”),输出字符串
		2.ROS_INFO(“s%”, msg.data.c_str()),输出一个字符串变量
		3.ROS_INFO(“I heard: [s%]”, msg.data.c_str()),输出一个字符串变量，这里的中括号不是必须的，输出时会直接显示这个中括号
		4.ROS_INFO(“I heard: [s%]”, msg->data.c_str()),输出一个指针变量
		5.ROS_INFO(“Publish Person Info: name:%s age:%d sex:%d”, person_msg.name.c_str(), person_msg.age, person_msg.sex)，按数据类型输出
*/

	    // 按照循环频率延时
	    loop_rate.sleep();
	}

	return 0;
}
